import {Directive, ElementRef, HostListener} from '@angular/core';
import {Platform} from 'ionic-angular';

/**
 * Generated class for the ForbidEmojiDirective directive.
 *
 * See https://angular.io/api/core/Directive for more info on Angular
 * Directives.
 */
@Directive({
    selector: 'ion-input[forbid-emoji]' // Attribute selector
})
export class ForbidEmojiDirective {

    constructor(public el: ElementRef, private platform: Platform) {
    }

    /// 禁止输入表情
    @HostListener('input', ['$event.target'])
    oninput() {
        let $input = this.el.nativeElement.querySelector('input');
        if (this.platform.is('cordova')) {
            $input.value = $input.value.replace(/(\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]|\ud83d[\ude80-\udeff])/g, '');
        }
    }
}
